<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>城市距离配置</title>
    <link rel="stylesheet" type="text/css" href="../ui/themes/black/easyui.css">
    <link rel="stylesheet" type="text/css" href="../ui/themes/icon.css">
    <script type="text/javascript" src="../ui/jquery.min.js"></script>
    <script type="text/javascript" src="../ui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../ui/easyloader.js"></script>

    <script type="text/javascript">
        easyloader.theme = "black";
        //页面加载
        $(document).ready(function () {
            loadGrid();
        });

        function doSearch() {
            $('#table').datagrid('load', {
                sitenum: $('#sitenum').val(),
                desc: $('#desc').val(),
                sitetype: $('#sitetype').combobox('getValue')
            });
        }

        //加载表格datagrid
        function loadGrid() {
            //加载数据
            $('#table').datagrid({
                width: 'auto',
                height: 'auto',
                striped: true,
                singleSelect: true,
                collapsible: true,
                rownumbers: true,
                pagination: true,
                method: 'get',
                url: '/site/page',
                //queryParams:{},
                loadMsg: '数据加载中请稍后……',
                columns: [[
                    {field: 'id', title: 'ID', sortable: true},
                    {field: 'sitenum', title: '站点ID', sortable: true},
                    {field: 'desc', title: '站点名称（描述）', sortable: true},
                    {field: 'sitetype', title: '站点类型', sortable: true},
                    {field: 'siteenv', title: '适用环境', sortable: true},
                    {field: 'sitemap', title: '相映射的测试/线上站点号', sortable: true},
                    {field: 'companyprefix', title: '航司前缀', sortable: true},
                    {field: 'checkprice', title: '验价方式', sortable: true},
                    {field: 'concurrentrestrict', title: '是否并发限制', sortable: true},
                    {field: 'flagshipinterface', title: '运价库接口选择', sortable: true},
                    {field: 'flightexcontext', title: '是否验价依赖搜索', sortable: true},
                    {field: 'kxmb', title: '是否在无线端展示', sortable: true},
                    {field: 'tmc', title: '是否在TMC展示', sortable: true},
                    {field: 'forbidtime', title: '禁用时间', sortable: true},
                    {field: 'limitprice', title: '是否限价', sortable: true},
                    {field: 'isDel', title: '是否删除', sortable: true},
                    {
                        field: 'createTime', title: '创建时间', sortable: true,
                        formatter: function (value, row, index) {
                            return getDate(value);
                        }
                    },
                    {
                        field: 'updateTime', title: '更新时间', sortable: true,
                        formatter: function (value, row, index) {
                            return getDate(value);
                        }
                    }
                ]]
            });
        }

        function getDate(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            var hour = date.getHours().toString();
            var minutes = date.getMinutes().toString();
            var seconds = date.getSeconds().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (seconds < 10) {
                seconds = "0" + seconds;
            }
            return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
        }

        function remove() {
            var row = $('#table').datagrid('getSelected');
            if (row) {
                $.messager.confirm('信息', '您确定要删除吗?', function (r) {
                    if (r) {
                        $.ajax({
                            url: '/site/remove',
                            type: 'POST',        //GET
                            async: true,         //或false,是否异步
                            data: {
                                id: row.id
                            },
                            timeout: 5000,       //超时时间
                            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                            beforeSend: function (xhr) {
                            },
                            success: function (data, textStatus, jqXHR) {
                                if (data.errorCode == "0") {
                                    msg(data.errorMsg, "info");
                                    loadGrid();
                                } else {
                                    msg(data.errorMsg, "error");
                                }

                            },
                            error: function (xhr, textStatus) {
                                $.messager.alert('信息', '删除失败!', 'error');
                            },
                            complete: function () {
                            }
                        })
                    }
                });
            }
        }

        function submitAddForm() {
            $('#addForm').form('submit', {
                dataType: "json",
                onSubmit: function () {
                    return $(this).form('enableValidation').form('validate');
                },
                success: function (data) {
                    $('#add').window('close');
                    var rs = $.parseJSON(data);
                    if (rs.errorCode == "0") {
                        doSearch();
                        msg(rs.errorMsg, "info");
                    } else {
                        msg(rs.errorMsg, "error");
                    }
                }
            });
        }

        function clearAddForm() {
            $('#addForm').form('clear');
        }

        function edit() {
            var row = $('#table').datagrid('getSelected');
            if (row) {
                $('#editForm').form('load', {
                    id: row.id,
                    sitenum: row.sitenum,
                    desc: row.desc,
                    sitetype: row.sitetype,
                    siteenv: row.siteenv,
                    sitemap: row.sitemap,
                    companyprefix: row.companyprefix,
                    checkprice: row.checkprice,
                    concurrentrestrict: row.concurrentrestrict,
                    flagshipinterface: row.flagshipinterface,
                    flightexcontext: row.flightexcontext,
                    kxmb: row.kxmb,
                    tmc: row.tmc,
                    forbidtime: row.forbidtime,
                    limitprice: row.limitprice
                });
                $('#edit').window('open');
            }
        }

        function submitEditForm() {
            $('#editForm').form('submit', {
                dataType: "json",
                onSubmit: function () {
                    return $(this).form('enableValidation').form('validate');
                },
                success: function (data) {
                    $('#edit').window('close');
                    var rs = $.parseJSON(data);
                    if (rs.errorCode == "0") {
                        loadGrid();
                        msg(rs.errorMsg, "info");
                    } else {
                        msg(rs.errorMsg, "error");
                    }
                }
            });
        }

        function msg(msg, tag) {
            using(['dialog', 'messager'], function () {
                $('#dd').dialog({
                    title: '消息',
                    width: 300,
                    height: 200
                });
                $.messager.show({
                    title: tag,
                    msg: msg,
                    timeout: 1000
                });
            });
        }
    </script>
</head>
<body>

<!-- 表格 -->
<table id="table" title="站点列表" data-options="rownumbers:true,toolbar:'#tb,#ft'" style="width: 100%">
</table>

<!-- 搜索 -->
<div id="tb" style="padding:2px 5px;">
    站点号: <input id="sitenum" class="easyui-textbox" style="width:110px">
    站点名称: <input id="desc" class="easyui-textbox" style="width:110px">
    站点类型:
    <select id="sitetype" class="easyui-combobox" style="width:110px">
        <option value=""></option>
        <option value="flagship">flagship</option>
        <option value="ota">ota</option>
        <option value="other">other(春秋)</option>
    </select>
    <a href="#" id="search" class="easyui-linkbutton" onclick="doSearch()" iconCls="icon-search">Search</a>
</div>
<div id="ft" style="padding:2px 5px;">
    <a href="#" onclick="$('#add').window('open')" class="easyui-linkbutton" iconCls="icon-add" plain="true"></a>
    <a href="#" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit" plain="true"></a>
    <a href="#" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove" plain="true"></a>
</div>

<!-- 添加 -->
<div id="add" class="easyui-window" title="添加站点" data-options="modal:true,closed:true,iconCls:'icon-save'"
     style="width:800px;height:500px;padding:10px;display: none">
    <div class="easyui-panel" title="添加" style="width:99%;padding:30px 60px;">
        <form id="addForm" action="/site/add" method="post">
            <div style="margin-bottom:20px;">
                <input class="easyui-textbox" name="sitenum" style="width:300px"
                       data-options="label:'站点号:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="desc" style="width:300px"
                       data-options="label:'描述:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="sitetype" label="站点类型:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="flagship">flagship</option>
                    <option value="ota">ota</option>
                    <option value="other">other(春秋)</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="siteenv" label="环境:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="test">test</option>
                    <option value="product">product</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="sitemap" style="width:300px"
                       data-options="label:'映射的测试/线上站点号:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="companyprefix" style="width:300px"
                       data-options="label:'航司前缀:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="checkprice" label="验价方式:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="airportcode">airportcode</option>
                    <option value="citycode">citycode</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="concurrentrestrict" label="是否并发限制:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="flagshipinterface" label="使用flagship新旧接口:"
                        data-options="required:true" style="width:300px">
                    <option value=""></option>
                    <option value="faredb">faredb</option>
                    <option value="yes">old</option>
                    <option value="yes">new</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="flightexcontext" label="是否验价依赖搜索:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="kxmb" label="是否在无线端展示:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="yes">yes</option>
                    <option value="no">no</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="tmc" label="是否在内部采购中展示:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="forbidtime" style="width:300px"
                       data-options="label:'禁用时间:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="limitprice" label="是否限价:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
        </form>
        <div style="text-align:center;padding:5px 0">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitAddForm()"
               style="width:80px">Submit</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearAddForm()" style="width:80px">Clear</a>
        </div>
    </div>
</div>

<!-- 编辑 -->
<div id="edit" class="easyui-window" title="编辑站点" data-options="modal:true,closed:true,iconCls:'icon-save'"
     style="width:800px;height:500px;padding:10px;display: none">
    <div class="easyui-panel" title="编辑" style="width:99%;padding:30px 60px;">
        <form id="editForm" action="/site/edit" method="post">

            <div style="margin-bottom:20px;">
                <input name="id" type="hidden"/>
                <input class="easyui-textbox" name="sitenum" style="width:300px"
                       data-options="label:'站点号:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="desc" style="width:300px"
                       data-options="label:'描述:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="sitetype" label="站点类型:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="flagship">flagship</option>
                    <option value="ota">ota</option>
                    <option value="other">other(春秋)</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="siteenv" label="环境:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="test">test</option>
                    <option value="product">product</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="sitemap" style="width:300px"
                       data-options="label:'映射的测试/线上站点号:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="companyprefix" style="width:300px"
                       data-options="label:'航司前缀:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="checkprice" label="验价方式:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="airportcode">airportcode</option>
                    <option value="citycode">citycode</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="concurrentrestrict" label="是否并发限制:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="flagshipinterface" label="使用flagship新旧接口:"
                        data-options="required:true" style="width:300px">
                    <option value=""></option>
                    <option value="faredb">faredb</option>
                    <option value="yes">old</option>
                    <option value="yes">new</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="flightexcontext" label="是否验价依赖搜索:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="kxmb" label="是否在无线端展示:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="yes">yes</option>
                    <option value="no">no</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="tmc" label="是否在内部采购中展示:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="forbidtime" style="width:300px"
                       data-options="label:'禁用时间:',required:true"/>
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="limitprice" label="是否限价:" data-options="required:true"
                        style="width:300px">
                    <option value=""></option>
                    <option value="no">no</option>
                    <option value="yes">yes</option>
                </select>
            </div>
        </form>
        <div style="text-align:center;padding:5px 0">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitEditForm()"
               style="width:80px">Submit</a>
        </div>
    </div>
</div>
</body>
</html>